"use strict";

module.exports = () => {
    /**
     *
     * @param {Egg.Context} ctx egg - context
     * @param {import("koa").Next} next koa - next
     */
    async function handle(ctx, next) {

        try {
            await next();
        } catch (error) {
            if (error.user && error.user === "user") {
                const status = error.status || error.statusCode;
                ctx.returnBody(status, error.message);
            } else {
                throw error;
            }
        }

    }

    return handle;
};
